class Solution(object):
    def permute(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        res = []
        self.dfs(res, [], nums, [False]*len(nums))
        return res

    def dfs(self, res, temp, nums, visited):
        if len(temp) == len(nums):
            t = temp[:]
            res.append(t)
            return
        for i in range(0, len(nums)):
            if visited[i] is False:
                visited[i] = True
                temp.append(nums[i])
                self.dfs(res, temp, nums, visited)
                visited[i] = False
                temp.pop()